package com.yitiao.data_algorithms.leetcode.editor.cn;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.ArrayList;
import java.util.List;

class BinaryTreePaths{
    // 2023-02-17 17:34:01
    public static void main(String[] args) {
        Solution solution = new BinaryTreePaths().new Solution();
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    List<String> ans = new ArrayList<>();
    public List<String> binaryTreePaths(TreeNode root) {
        dfs(root,"");
        return ans;
    }

    private void dfs(TreeNode root,String path) {
        if (root==null)return;

        if (root.left==null&&root.right==null){
            path+=Integer.valueOf(root.val).toString();
            ans.add(path);
        }else {
            path+=Integer.valueOf(root.val).toString()+"->";
            dfs(root.left,path);
            dfs(root.right,path);
        }

    }
}
//leetcode submit region end(Prohibit modification and deletion)

}